package com.exercise;

import javax.swing.tree.TreeNode;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: ws
 * Date: 2023-01-10
 * Time: 19:56
 */
public class Test {
    public static void main(String[] args) {
        String s = null;
        String s1 = null;
        System.out.println(s == s1);

    }
}
//https://leetcode.cn/problems/subtree-of-another-tree/submissions/394382039/
//官解哈希法，字节面试
/**
 * Definition for a binary tree node.
 * public class TreeNode {
 *     int val;
 *     TreeNode left;
 *     TreeNode right;
 *     TreeNode() {}
 *     TreeNode(int val) { this.val = val; }
 *     TreeNode(int val, TreeNode left, TreeNode right) {
 *         this.val = val;
 *         this.left = left;
 *         this.right = right;
 *     }
 * }
 */
class Solution {
    public boolean isSubtree(TreeNode root, TreeNode subRoot) {
        if (root == null) {
            return false;
        } else if (root.val == subRoot.val && isSameTree(root, subRoot)) {
            return true;
        } else {
            return isSubtree(root.left, subRoot) || isSubtree(root.right, subRoot);
        }
    }

    //判断是否是同一棵树
    private boolean isSameTree(TreeNode s, TreeNode t) {
        return (s == t) || (s != null && t != null && s.val == t.val
                && isSameTree(s.left, t.left) && isSameTree(s.right, t.right));
    }
}